<template>
  <div class="container">
    <div id="barChart" style="height:100%" />
  </div>
</template>

<script>
import { everyProvinceSalesVolume } from './data.js'
const echarts = require('echarts/lib/echarts')
require('echarts/lib/component/grid')
require('echarts/lib/chart/bar')
require('echarts/lib/component/title')
require('echarts/lib/component/tooltip')

export default {
  data () {
    return {
      barChart: null,
      everyProvinceSalesVolume
    }
  },

  mounted () {
    this.init()
    this.getBarChart()
  },

  methods: {
    init () {
      this.barChart = echarts.init(document.getElementById('barChart'))
      window.addEventListener('resize', () => {
        this.barChart.resize()
      })
    },

    getBarChart () {
      const option = {
        title: {
          text: '中国各省级行政区销售额柱状图',
          left: 'center'
        },
        tooltip: {
          trigger: 'axis'
        },
        xAxis: {
          type: 'category',
          data: this.everyProvinceSalesVolume.map(i => i.label),
          axisLabel: {
            rotate: 45,
            interval: 0
          }
        },
        yAxis: {
          type: 'value',
          name: '元',
          nameLocation: 'end',
          nameTextStyle: {
            align: 'right',
            padding: [0, 12, 5, 0]
          }
        },
        series: [
          {
            data: this.everyProvinceSalesVolume.map(i => i.value),
            type: 'bar'
          }
        ]
      }
      this.barChart.setOption(option)
    }
  }
}
</script>

<style lang="less" scoped>
.container {
  height: 100%;
  background-color: white;
  overflow-y: auto;
}
</style>
